package xiangmu.schoolpaper.controller.system;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xiangmu.schoolpaper.exception.ContentNullException;
import xiangmu.schoolpaper.pojo.DTO.MajorAndIdDTO;
import xiangmu.schoolpaper.pojo.VO.MajorAndIdVO;
import xiangmu.schoolpaper.pojo.VO.TemplateTypeVO;
import xiangmu.schoolpaper.result.Result;
import xiangmu.schoolpaper.service.impl.system.TemplateTypeServiceImpl;

@Slf4j
@RestController
@RequestMapping("/system")
@Tag(name="模板类型数据接口")
public class TemplateTypeController {
    @Autowired
    public TemplateTypeServiceImpl templateTypeServiceImpl;

    @GetMapping("/templateType/updateTemplateType")
    @Operation(summary = "修改模板参数")
    public Result updateTemplateType(@RequestBody TemplateTypeVO templateType){
        log.info("修改模板参数{}",templateType);
        templateTypeServiceImpl.updateTemplateType(templateType);
        return Result.success();
    }
    @GetMapping("/templateType/deleteTemplateType")
    @Operation(summary = "删除模板参数")
    public Result disableTemplateType(@RequestBody TemplateTypeVO ids){
        log.info("删除id为{}的模板参数",ids);

        templateTypeServiceImpl.disableTemplateType(ids);

        return Result.success();
    }
    @GetMapping("/major/getMajor")
    @Tag(name="获取数据字典-专业数据")
    public Result getMajor(Integer id){
        log.info("获取数据字典-专业数据");
        MajorAndIdVO majorAndIdVO = templateTypeServiceImpl.getMajor(id);
        if(majorAndIdVO!=null){
            return Result.success(majorAndIdVO);
        }else{
            throw new ContentNullException("没有此id对应的专业");
        }
    }
    @PostMapping("/major/addMajor")
    @Tag(name="添加数据字典-专业数据")
    public Result addMajor(@RequestBody MajorAndIdVO majorAndIdVO){
        log.info("添加数据字典-专业数据{}",majorAndIdVO);
        Integer result=templateTypeServiceImpl.addMajor(majorAndIdVO);
        if(result>0){
            return Result.success(result);
        }else{
            return Result.error("添加失败");
        }
    }
    @PostMapping("/major/deleteMajor")
    @Tag(name="删除数据字典-专业数据")
    public Result deleteMajor( Integer id){
        log.info("删除数据字典-专业数据{}",id);
        templateTypeServiceImpl.deleteMajor(id);
        return Result.success();
    }
    @PostMapping("/major/updateMajor")
    @Tag(name="修改数据字典-专业数据")
    public Result updateMajor(@RequestBody MajorAndIdDTO majorAndIdDTO){
        log.info("修改数据字典-专业数据{}",majorAndIdDTO);
        templateTypeServiceImpl.updateMajor(majorAndIdDTO);
        return Result.success();
    }
}
